<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
    <style>
        .title {
            font-size: 40px;
            -webkit-text-stroke: 1px #fbfbfb;
            -webkit-text-fill-color: transparent;
        }
        .title2 {
            font-size: 40px;
            background: linear-gradient(to bottom,white,black);
            -webkit-text-fill-color: transparent;
            -webkit-background-clip: text;
        }

    </style>
</head>
<body style="background-color: #afb6c5">
<div class="kvf-user-login" id="kUserLoginBox">

    <div class="kvf-user-login-main">
        <div class="kvf-user-login-box kvf-user-login-header">
            <h2 class="title">kvfAdmin</h2>
        </div>
        <div class="layui-form kvf-user-login-box">
            <div class="layui-form-item">
                <label class="kvf-user-login-icon layui-icon layui-icon-username" for="kUserLoginUsername"></label>
                <input type="text" name="username" id="kUserLoginUsername" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="kvf-user-login-icon layui-icon layui-icon-password" for="kUserLoginPassword"></label>
                <input type="password" name="password" id="kUserLoginPassword" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="kvf-user-login-icon layui-icon layui-icon-vercode" for="kUserLoginVercode"></label>
                        <input type="text" name="vercode" id="kUserLoginVercode"  placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img th:src="@{/captcha.jpg}" class="kvf-user-login-codeimg" id="kUserGetVerCode" title="点击刷新验证码">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="rememberMe" lay-skin="primary" title="记住密码">
                <a href="forget.html" class="kvf-user-jump-change" style="margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button id="submitBtn" class="layui-btn layui-btn-fluid" lay-submit lay-filter="kUserLoginSubmit">登 录</button>
            </div>
            <!--<div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号登入</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="reg.html" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
            </div>-->
        </div>
    </div>

    <div class="layui-trans kvf-user-login-footer">
        <p>© 2019 <a href="https://tools.kalvinbg.cn" target="_blank">kvf.com</a></p>
    </div>

</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //提交
        form.on('submit(kUserLoginSubmit)', function(obj) {
            //请求登入接口
            kvfKit.aPost(api.login, obj.field, function (r) {
                if (r.code === req.status.ok) {
                    // todo 请求成功后，写入 access_token
                    /*layui.data(setter.tableName, {
                        key: setter.request.tokenName
                        ,value: res.data.access_token
                    });*/
                    // 登入成功的提示与跳转
                    layer.msg('登录成功', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 500
                    }, function(){
                        location.href = api.homeView; // kvf-admin首页
                    });

                } else {
                    if (r.msg.indexOf('验证码') !== -1) {
                        kvfKit.errorMsg(r.msg + '，请重试。');
                        refreshVerCode();
                    } else {
                        kvfKit.errorMsg(r.msg);
                        refreshVerCode();
                    }
                }
            });
        });

        // 绑定监听回车事件
        kvfKit.bindEnterEventForLayuiForm();


        $('#kUserGetVerCode').on('click', function () {
            refreshVerCode();
        });

        // 刷新图片验证码
        function refreshVerCode() {
            $('#kUserGetVerCode').attr('src', api.captchaUrl);
            $('#kUserLoginVercode').val('');
        }

    })
</script>
</body>
</html>